package com.shishi.fast.common.push;

import com.alibaba.fastjson.JSONObject;
import com.shishi.fast.common.util.HttpClientHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;

/**
 * @Author mm
 * @Date 2022/12/12 14:56
 * @Description TODO
 */
@Slf4j
@Component
public class MesPushUtils {

    // AllInEAP公众号，推送成功之前需要先在公众号进行注册
    private final static String wxPushUrl = "http://49.235.254.223:9300/WechatService.asmx/SendTemplateMessage";

    public String wxPush(MesPushRequest request) {
        SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String param = "phone=" + request.getPhone() + "&title=" + request.getTitle() + "&content=" + request.getContent() + "&time=" + sim.format(request.getTime()) + "&memo=" + request.getMemo();
        String resultString = HttpClientHelper.sendHttpPost(wxPushUrl, param, "");
        JSONObject jsonObject = JSONObject.parseObject(resultString);
        if ("0".equals(jsonObject.get("errcode").toString())) {
            return "成功";
        } else {
            return "失败:" + jsonObject.get("errmsg");
        }
    }
}
